package com.neuedu.springmvc;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyExceptionResolver implements HandlerExceptionResolver {

    /**
     * 处理异常的方法 resolveException
     * @param request
     * @param response
     * @param handler  控制器
     * @param ex      产生的异常对象
     * @return
     */
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

        request.setAttribute("msg",ex.getMessage());

        //记录下错误，并写入到数据库

        ModelAndView mav = new ModelAndView();

        mav.setViewName("/error/500");

        return mav;
    }
}